package com.ewzj.bigdata.mvp.ui.fragment

import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ewzj.bigdata.R
import com.ewzj.bigdata.app.extensions.initcolor
import com.ewzj.bigdata.di.component.DaggerRealNewsFragmentComponent
import com.ewzj.bigdata.di.module.RealNewsFragmentModule
import com.ewzj.bigdata.mvp.contract.RealNewsFragmentContract
import com.ewzj.bigdata.mvp.presenter.RealNewsFragmentPresenter
import com.ewzj.bigdata.mvp.ui.adapter.InfoAdapter
import com.jess.arms.base.BaseFragment
import com.jess.arms.di.component.AppComponent
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration
import kotlinx.android.synthetic.main.fragment_realnew.*

/**
 * author:zhangjing
 * 作用:
 * return:
 */
class RealNewsFragment:BaseFragment<RealNewsFragmentPresenter>(),RealNewsFragmentContract.View{
    override fun initRecylerviewAdapter(adapter: InfoAdapter) {
        rvnews.adapter=adapter
    }

    companion object {
        fun newInstance(): RealNewsFragment {
            val fragment = RealNewsFragment();
            val args = Bundle()
            fragment.arguments = args;
            return fragment
        }
    }
    override fun setupFragmentComponent(appComponent: AppComponent?) {
        DaggerRealNewsFragmentComponent.builder()
                .appComponent(appComponent)
                .realNewsFragmentModule(RealNewsFragmentModule(this))
                .build()
                .inject(this)
    }

    override fun initView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
        val view=inflater!!.inflate(R.layout.fragment_realnew,null,false);
        return view
    }

    override fun initData(savedInstanceState: Bundle?) {
        initBaseview()
        mPresenter.initAdapter(rvnews)
        if (rvnews.adapter==null) return
        mPresenter.initFirstData()
    }
    fun initBaseview(){
        swipeRefreshLayout.initcolor()
        rvnews.setLayoutManager(LinearLayoutManager(activity))
        rvnews.addItemDecoration(HorizontalDividerItemDecoration.Builder(activity).colorResId(R.color.colorf7).size(1).build())
        swipeRefreshLayout.setOnRefreshListener { mPresenter.initFirstData() }
    }
    override fun setData(data: Any?) {

    }

    override fun showLoading() {
        swipeRefreshLayout.isRefreshing=true
    }

    override fun launchActivity(intent: Intent?) {
        swipeRefreshLayout.isRefreshing=false
    }

    override fun hideLoading() {
        swipeRefreshLayout.isRefreshing=false
    }

    override fun killMyself() {

    }

    override fun showMessage(message: String?) {

    }

    override fun onResume() {
        super.onResume()
        mPresenter.onreusme()
    }
}